﻿using FileMonitor.Configuration.Prototype;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Specialized;
using FileUtility;
using FileMonitor.Configuration.Prototype.BizProcess;

namespace TestProject
{
    
    
    /// <summary>
    ///This is a test class for ProcedureProcessDataControllerTest and is intended
    ///to contain all ProcedureProcessDataControllerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ProcedureProcessDataControllerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion





        /// <summary>
        ///A test for ParseNameValueCollectionToSqlParams
        ///</summary>
        //[TestMethod()]
        //public void ParseNameValueCollectionToSqlParamsTest()
        //{
        //    string Name = "Procedure_FrocastLogic"; // TODO: Initialize to an appropriate value
        //    ProcedureProcess target = new ProcedureProcess(Name); // TODO: Initialize to an appropriate value
        //    NameValueCollection values = new NameValueCollection(); // TODO: Initialize to an appropriate value
        //    values.Add("PlantCode", "AHEH");
        //    values.Add("TransType", "Read");

        //    string expected = "@PlantCode='AHEH',@TransType='Read'"; // TODO: Initialize to an appropriate value
        //    string actual;
        //    actual = target.ParseNameValueCollectionToSqlParams(values);
        //    Assert.AreEqual(expected, actual);
            
        //}

        /// <summary>
        ///A test for ExcuteOneWay
        ///</summary>
        [TestMethod()]
        public void ExcuteOneWayTest()
        {
            string Name = "Procedure_FrocastLogic"; // TODO: Initialize to an appropriate value
            ProcedureProcess target = new ProcedureProcess(Name); // TODO: Initialize to an appropriate value
            target.TimeOut = "3600";
            target.TargetDatabaseName = "BusinessDB";
            target.TargetProcedure = "IntSaveForecastFromSAPExchangeDB_SP";//111123/BizForecast_Process_SP
            SqlDataBaseExtender targetDb = new SqlDataBaseExtender("Database=EfoxNC;Server=10.157.45.88;User Id=sa;Password=Aa000000;"); // TODO: Initialize to an appropriate value
            NameValueCollection task = new NameValueCollection(); // TODO: Initialize to an appropriate value
            task.Add("BatchId", "6a7cdf49-ffe6-4f28-9eef-23ccf19626dc");
            task.Add("TransType", "PreProcess");
            task.Add("Owner_I", "AHLN");
            target.ExcuteOneWay(targetDb, task);
        }

        /// <summary>
        ///A test for ExcuteTwoWay
        ///</summary>
        [TestMethod()]
        public void ExcuteTwoWayTest()
        {
            string Name = "Procedure_FrocastLogic"; // TODO: Initialize to an appropriate value
            ProcedureProcess target = new ProcedureProcess(Name); // TODO: Initialize to an appropriate value
            target.TimeOut = "3600";
            target.SourceDatabaseName = "DefaultExchangeDB";
            target.TargetDatabaseName = "BusinessDB";
            target.BizProcedure = "BizForecast_Process_SP";
            target.TargetParams = "[TransType,IMPORTFCST]";
            target.TargetProcedure="IntSaveForecastFromSAPExchangeDB_SP";
            SqlDataBaseExtender sourceDb = new SqlDataBaseExtender("Database=SAPExchangeDB;Server=10.157.45.88;User Id=sa;Password=Aa000000;");
            SqlDataBaseExtender targetDb = new SqlDataBaseExtender("Database=EfoxNC;Server=10.157.45.88;User Id=sa;Password=Aa000000;"); // TODO: Initialize to an appropriate value
            NameValueCollection task = new NameValueCollection(); // TODO: Initialize to an appropriate value
            task.Add("BatchId", "6a7cdf49-ffe6-4f28-9eef-23ccf19626dc");
            task.Add("TransType", "PreProcess");
            task.Add("Owner_I", "AHLN");
            task.Add("Owner", "AHLN");

            target.ExcuteTwoWay(sourceDb,targetDb, task);
            System.Threading.Thread.Sleep(1000);
            target.ExcuteTwoWay(sourceDb, targetDb, task);

        }

        /// <summary>
        ///A test for Excute
        ///</summary>
        [TestMethod()]
        public void ExcuteTest()
        {
            string Name = "Procedure_FrocastLogic"; // TODO: Initialize to an appropriate value
            ProcedureProcess target = new ProcedureProcess(Name); // TODO: Initialize to an appropriate value
            target.TimeOut = "3600";
            target.SourceDatabaseName = "DefaultExchangeDB";
            target.TargetDatabaseName = "BusinessDB";
            target.BizProcedure = "BizForecast_ProcessNew_SP";
            target.TargetParams = "[TransType,IMPORTFCST]";
            target.TargetProcedure = "IntSaveForecastFromSAPExchangeDB_SP";
            SqlDataBaseExtender sourceDb = new SqlDataBaseExtender("Database=SAPExchangeDB;Server=10.157.45.88;User Id=sa;Password=Aa000000;");
            SqlDataBaseExtender targetDb = new SqlDataBaseExtender("Database=EfoxNC;Server=10.157.45.88;User Id=sa;Password=Aa000000;"); // TODO: Initialize to an appropriate value
            NameValueCollection task = new NameValueCollection(); // TODO: Initialize to an appropriate value
            task.Add("BatchId", "6a7cdf49-ffe6-4f28-9eef-23ccf19626dc");
            task.Add("TransType", "PreProcess");
            task.Add("Owner_I", "AHLN");
            task.Add("Owner", "AHLN");

            target.Excute(task);
            
        }

        /// <summary>
        ///A test for Copy
        ///</summary>
        [TestMethod()]
        public void CopyTest()
        {
            string Name = string.Empty; // TODO: Initialize to an appropriate value
            ProcedureProcess target = FileMonitor.Configuration.Providers.ProviderService.GetProvider().GetAllProcedureProcess()["Procedure_HPFrocastLogic"];
         //   BizProcessBase expected = null; // TODO: Initialize to an appropriate value
         //   BizProcessBase actual;
            BizProcessBase actual = target.Copy();
            Assert.AreEqual("1", actual.NextStatus);
         //   Assert.Inconclusive("Verify the correctness of this test method.");
        }
    }
}
